import { Component, OnInit, Injector } from '@angular/core';
import { CityListComponent } from '../cityList';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { HttpClient } from "@angular/common/http";
import { NgZorroPageBaseComponent } from '../../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import {
  PagedResultDto, ClassInfoOutput, PagerSearchInput, HttpService, BaseComponentConfig,
  CustomNavigation, KeyValueOutput, SearchValue
} from '../../..';
@Component({
  selector: 'app-school-add',
  templateUrl: './school-add.component.html',
  styleUrls: ['./school-add.component.scss']
})
export class SchoolAddComponent extends NgZorroPageBaseComponent implements OnInit {
  radioValue = 'true';
  selectedProvince;
  selectedCity;
  cityData: any;
  time = "2018-07-30";
  schoolName;
  personName = "";
  personPhone = "";
  personEmail = "";
  personUserName = "";
  personPassword = "";
  collegelName;
  provinceData: any;
  mess: any;
  resute = [];
  resute1 = [];
  resultxy = [];
  listEntitiesscl;
  timelist = new Array();
  ilist = 0;
  listEntitiesdata: any;
  aclear;
  ngOnInit() {
    this.IniObserver.subscribe(sb => {
      this.getEntityList();
    });
  }
  constructor(injecter: Injector,
    public http: HttpService) {
    super(injecter,
      new BaseComponentConfig(
        "School/GetAllSchool",
        "",
        "",
        "",
        "",
        "id",
        "",
        "学校管理",
        [],
        "",
        { Edit: false, Dell: false },
      ));
    const city = new CityListComponent;
    this.cityData = city.cityDatas;
    this.provinceData = city.provinceDatas;
    const datalist = { "Name": "" };
    this.http.post<any>("School/GetSchoolToTen", datalist).then(e => {
      this.listEntitiesdata = e;

    });

  }

  provinceChange(value: string): void {
    this.selectedCity = this.cityData[value][0];
  }
  /**
   * 保存學校信息
   *
   */


  async serve(type: string) {

    const that = this;
    that.resute = [];
    // that.resute1=[];
    // let address=this.selectedProvince+","+this.selectedCity;
    const data = {
      "enableTime": this.time, "enableOrDiscontinuation": this.radioValue, "academeId": this.collegelName, "academeName": "1",
      "userName": this.personUserName, "userPwd": this.personPassword, "personId": 0, "isActive": true, "photoUrl": "1", "userRoleType": 1, "personName": this.personName, "personNo": "1", "phoneNumber": this.personPhone, "email": this.personEmail
    };
    

    Object.keys(data).forEach(function (trait) {
      that.resute.push(data[trait]);
    });
    let a = 0;

    for (let i = 0; i < this.resute.length; i++) {
      if (this.resute[i] === "" || this.resute[i] === "undefined") {
        that.message.info('请填写完整');
        return false;
      } else {
        a++;
        if (a === this.resute.length) {

          await that.http.post<any>("SchoolAcademeManager/CreatSchoolManager", data);

          this.message.create(type, `保存成功`);

          this.router.navigate(['app/schoolindex']);
        }
      }
    }
    //  }
  }

  delete() {

  }
  async provinceChangesol(e) {
    this.resultxy = await this.http.get<any>('School/GetAllAcademeBySchool?input=' + e);
    this.collegelName = "";
  }

  async searchChange(searchText: string) {
    const that = this;
    clearTimeout(this.aclear);
    this.aclear = setTimeout(() => {
      that.sealist(searchText);
    }, 1000);


  }
  sealist(i) {
    const datalist = { "Name": i };
    this.listEntitiesdata = [];
    this.http.post<any>("School/GetSchoolToTen", datalist).then(e => {
      this.listEntitiesdata = e;

    });


  }


}

